package com.sharding.service;

import com.sharding.entity.Goods;
import com.sharding.mapper.GoodsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Desc:
 * Date:    2023/2/27
 *
 * @author WanYangWei
 */
@Service
public class GoodsService {
    @Autowired
    private GoodsRepository goodsRepository;

    public void saveGoodsInfo(Goods goods) {
        goodsRepository.save(goods);
    }

    public List<Goods> selectAll() {
        return goodsRepository.selectAll();
    }

    public Goods getGoodsInfo(Long id) {
        return goodsRepository.selectById(id);
    }

    public List<Goods> selectByCreateTime(String createTime) {
        return goodsRepository.selectByCreateTime(createTime);
    }

    public List<Goods> rangeByCreateTime(String beginTime, String endTime) {
        Map<String, String> param = new HashMap<>();
        param.put("beginTime", beginTime);
        param.put("endTime", endTime);
        return goodsRepository.rangeByCreateTime(param);
    }

    public int updateById(Goods goodsInfo) {
        return goodsRepository.updateById(goodsInfo);
    }
}
